package com.mingqijia.gassafety.console.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mingqijia.gassafety.authority.api.resp.config.DictionaryItemRespDTO;
import com.mingqijia.gassafety.db.entity.auth.DictionaryItemEntry;
import com.mingqijia.gassafety.shared.utils.commonUtils.PageUtil;
import com.mingqijia.gassafety.webserver.response.sk.AlarmSupplierListVo;
import com.mingqijia.gassafety.webserver.service.EquipmentManufacturerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;


/**
 * @author  zm
 * @className   EquipmentManufacturerController
 * @Description
 * @createTime 2024/7/25 14:21
 */

@Slf4j
@RestController
@RequestMapping("/business/v1/equipment_manufacturer")
@Api(tags = "厂商管理")
public class EquipmentManufacturerController {


    @Autowired
    private EquipmentManufacturerService equipmentManufacturerService;


    @ApiOperation(value = "查询厂商列表")
    @GetMapping("/list")
    public PageUtil<DictionaryItemRespDTO> queryList() {
        PageUtil<DictionaryItemRespDTO>  results = new PageUtil<>();
        Page<DictionaryItemEntry> pager = new Page<>(1, 1000);
        List<DictionaryItemRespDTO> entities = results.getList();
        List<AlarmSupplierListVo> list = equipmentManufacturerService.queryList();
        log.info("list.size():{}", list.size());
        if (CollectionUtils.isNotEmpty(list)) {
            entities = list.stream().map(item -> {
                DictionaryItemRespDTO dictionaryItemRespDTO = new DictionaryItemRespDTO();
                dictionaryItemRespDTO.setId(item.getAlarmSystemCode());
                dictionaryItemRespDTO.setValue(item.getAlarmSystemCode());
                dictionaryItemRespDTO.setName(item.getMsName());
                return dictionaryItemRespDTO;
            }).collect(Collectors.toList());
        }
        pager.setTotal(entities.size());
       return PageUtil.init(pager, entities);
    }

}
